/*
 Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
 Original sources are available at www.latestbit.com

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

 SessionId.hpp. Created on: 02.12.2009 16:15:44 
 */

#ifndef SESSIONID_HPP_
#define SESSIONID_HPP_

#include "smartobjects/SmartObjectsDefs.hpp"
#include "smartobjects/network/ConnectionHandler.hpp"

namespace smartobjects {

template<typename T>
class SessionId : public virtual RefObject {
public:
	inline SessionId() : m_poConnectionHandler( NULL ) {

	}

	virtual ~SessionId() {
		releaseAndClear(m_poConnectionHandler);
	}

	inline void setId(T oValue) {
		m_oValue = oValue;
	}

	inline const T& getId() const {
		return m_oValue;
	}

	inline void setConnectionHandler(ConnectionHandler* poConnectionHandler) {
		setNewRefObject(m_poConnectionHandler, poConnectionHandler);
	}

	inline ConnectionHandler* getConnectionHandler() const {
		return m_poConnectionHandler;
	}

protected:
	T m_oValue;
	ConnectionHandler* m_poConnectionHandler;
};

// Partial template specialization for RefObject pointers
template<typename T>
class SessionId<T*> : public RefObject {
public:
	inline SessionId() : m_poValue(NULL), m_poConnectionHandler( NULL ) {

	}

	virtual ~SessionId() {
		releaseAndClear(m_poValue);
		releaseAndClear(m_poConnectionHandler);
	}

	inline void setId(T* oValue) {
		m_poValue = oValue;
	}

	inline const T* getId() const {
		return m_poValue;
	}

	inline void setConnectionHandler(ConnectionHandler* poConnectionHandler) {
		setNewRefObject(m_poConnectionHandler, poConnectionHandler);
	}

	inline ConnectionHandler* getConnectionHandler() const {
		return m_poConnectionHandler;
	}

protected:
	T* m_poValue;
	ConnectionHandler* m_poConnectionHandler;
};

}

#endif /* SESSIONID_HPP_ */
